﻿@page "/users"
@inherits PageBase

<PageContainer>
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem><Icon Type="home"></Icon></BreadcrumbItem>
            <BreadcrumbItem><Icon Type="user"></Icon><span>用户中心</span></BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <ChildContent>
        <Card>
            <Table TItem="UserDto"
                   DataSource="@users"
                   Bordered=@true
                   Size=@TableSize.Small>
                <Column @bind-Field="@context.Id" Title="Id" Sortable="false"></Column>
                <Column @bind-Field="@context.Username" Title="用户名" Sortable="false"></Column>
                <Column @bind-Field="@context.Type" Title="来源" Sortable="false"></Column>
                <Column @bind-Field="@context.Identity" Title="唯一标识" Sortable="false"></Column>
                <Column @bind-Field="@context.Name" Title="昵称" Sortable="false"></Column>
                <Column @bind-Field="@context.Avatar" Title="头像" Sortable="false">
                    <Avatar Size="large" Icon="user" Src="@context.Avatar" />
                </Column>
                <Column @bind-Field="@context.Email" Title="邮箱" Sortable="false"></Column>
                <Column @bind-Field="@context.IsAdmin" Title="登录权限" Sortable="false">
                    <Switch @bind-Value="@context.IsAdmin" Disabled="@(users.FirstOrDefault().Id == context.Id)"
                            OnChange="@(async () => await ChangeIsAdminAsync(context.Id, context.IsAdmin))"></Switch>
                </Column>
                <Column @bind-Field="@context.CreatedAt" Title="创建时间" Sortable="false"></Column>
                <ActionColumn Title="操作">
                    <Space Size="@("small")">
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" OnClick="_ => Open(context.Id)">编辑</Button>
                            <Popconfirm Title="确定删除吗?"
                                        Icon="close-circle"
                                        Disabled="@(users.FirstOrDefault().Id == context.Id)"
                                        OnConfirm="(async () => await DeleteAsync(context.Id))">
                                <Button Danger Disabled="@(users.FirstOrDefault().Id == context.Id)">删除</Button>
                            </Popconfirm>
                        </SpaceItem>
                    </Space>
                </ActionColumn>
            </Table>
        </Card>
        <Drawer Closable="true"
                Visible="@visible"
                Placement="right"
                Title='("编辑个人信息")'
                Width="@drawerWidth"
                OnClose="_ => Close()">
            <Form Model="@input"
                  LabelColSpan="4"
                  WrapperColSpan="16"
                  OnFinish="HandleSubmit">
                <FormItem>
                    <Row>
                        <AntDesign.Col Span="12" Offset="12">
                            <Avatar Size="64" Icon="user" Src="@context.Avatar" />
                        </AntDesign.Col>
                    </Row>
                </FormItem>
                <FormItem Label="用户名">
                    <Input @bind-Value="@context.Username" />
                </FormItem>
                <FormItem Label="昵称">
                    <Input @bind-Value="@context.Name" />
                </FormItem>
                <FormItem Label="邮箱">
                    <Input @bind-Value="@context.Email" />
                </FormItem>
                <FormItem Label="头像">
                    <Input @bind-Value="@context.Avatar" />
                </FormItem>
                <FormItem WrapperColOffset="4" WrapperColSpan="16">
                    <Button Type="@ButtonType.Primary" HtmlType="submit">保存</Button>
                    <Button OnClick="_ => OpenPasswordBox()">我要修改密码</Button>
                </FormItem>
            </Form>
        </Drawer>
        <Drawer Closable="true"
                Visible="@visible2"
                Placement="right"
                Title='("修改密码")'
                Width="500"
                OnClose="_ => ClosePasswordBox()">
            <Form Model="model"
                  LabelColSpan="4"
                  WrapperColSpan="16"
                  OnFinish="HandleUpdatePasswordSubmit">
                <FormItem Label="密码">
                    <InputPassword @bind-Value="@model.Password" />
                </FormItem>
                <FormItem WrapperColOffset="4" WrapperColSpan="16">
                    <Button Type="@ButtonType.Primary" HtmlType="submit">保存</Button>
                </FormItem>
            </Form>
        </Drawer>
    </ChildContent>
</PageContainer>